﻿using System.Text;

namespace csharpcl
{
    public class GPUDevice
    {
        public string Name { get; private set; }
        public ulong ID { get; private set; }
        public string Version { get; private set; }

        public long MaxComputeUnits { get; private set; }
        public long PECount { get; private set; }
        public string Extensions { get; private set; }

        public ulong PlatformID { get; private set; }

        public int MaxWorkGroupSize { get; private set; }
        public uint MaxWorkItemDimensions { get; private set; }
        public long[] MaxWorkItemSizes { get; private set; }

        public GPUDevice(ulong pid, ulong did)
        {
            PlatformID = pid;
            ID = did;
        }

        public void Init()
        {
            Name = Introp.GetDeviceName(ID);
            Version = Introp.GetDeviceVersion(ID);
            Extensions = Introp.GetDeviceExtensions(ID);
            MaxComputeUnits = Introp.GetDeviceMaxComputeUnits(ID);
            PECount = Introp.GetDevicePECount(ID);
            MaxWorkGroupSize = Introp.GetDeviceMaxWorkGroupSize(ID);
            MaxWorkItemDimensions = Introp.GetDeviceMaxWorkItemDimensions(ID);
            MaxWorkItemSizes = Introp.GetDeviceMaxWorkItemSizes(ID);
        }
        public string ToStringEx()
        {
            var builder = new StringBuilder();
            builder.AppendLine("设备名称:   \t" + Name);
            builder.AppendLine("设备ID:   \t" + ID);
            builder.AppendLine("OpenCL版本:\t" + Version);
            builder.AppendLine("CU数量:   \t" + MaxComputeUnits);
            builder.AppendLine("PE数量:   \t" + PECount);
            builder.AppendLine("最大工作项维度:   \t" + MaxWorkItemDimensions);
            builder.AppendLine("最大工作组大小:   \t" + MaxWorkGroupSize);
            for (int i = 0; i < MaxWorkItemSizes.Length; i++)
            {
                builder.AppendLine("最大工作项维度值:   \t" + MaxWorkItemSizes[i]);
            }

            builder.AppendLine("扩展:     \t" + Extensions);
            return builder.ToString();
        }
    }
}